! function(factory) {
    if ('function' === typeof define && define.amd) define(['jquery'], factory);
    else if ('object' === typeof exports) factory(require('jquery'));
    else factory(jQuery)
}(function($, undefined) {
    function timeZoneAbbreviation() {
        var abbreviation, date, formattedStr, i, len, matchedStrings, ref, str;
        if ((formattedStr = (null != (ref = (date = (new Date).toString()).split('(')[1]) ? ref.slice(0, -1) : 0) || date.split(' ')) instanceof Array) {
            matchedStrings = [];
            for (var i = 0, len = formattedStr.length; i < len; i++)
                if ((abbreviation = null !== (ref = (str = formattedStr[i]).match(/\b[A-Z]+\b/))) ? ref[0] : 0) matchedStrings.push(abbreviation);
            formattedStr = matchedStrings.pop()
        }
        return formattedStr
    }

    function UTCDate() { return new Date(Date.UTC.apply(Date, arguments)) }
    if (!('indexOf' in Array.prototype)) Array.prototype.indexOf = function(find, i) {
        if (i === undefined) i = 0;
        if (i < 0) i += this.length;
        if (i < 0) i = 0;
        for (var n = this.length; i < n; i++)
            if (i in this && this[i] === find) return i;
        return -1
    };
    var Datetimepicker = function(element, options) {
        var that = this;
        this.element = $(element);
        this.container = options.container || 'body';
        this.language = options.language || this.element.data('date-language') || 'en';
        this.language = this.language in dates ? this.language : this.language.split('-')[0];
        this.language = this.language in dates ? this.language : 'en';
        this.isRTL = dates[this.language].rtl || !1;
        this.formatType = options.formatType || this.element.data('format-type') || 'standard';
        this.format = DPGlobal.parseFormat(options.format || this.element.data('date-format') || dates[this.language].format || DPGlobal.getDefaultFormat(this.formatType, 'input'), this.formatType);
        this.isInline = !1;
        this.isVisible = !1;
        this.isInput = this.element.is('input');
        this.fontAwesome = options.fontAwesome || this.element.data('font-awesome') || !1;
        this.bootcssVer = options.bootcssVer || (this.isInput ? this.element.is('.form-control') ? 3 : 2 : this.bootcssVer = this.element.is('.input-group') ? 3 : 2);
        this.component = this.element.is('.date') ? 3 === this.bootcssVer ? this.element.find('.input-group-addon .glyphicon-th, .input-group-addon .glyphicon-time, .input-group-addon .glyphicon-remove, .input-group-addon .glyphicon-calendar, .input-group-addon .fa-calendar, .input-group-addon .fa-clock-o').parent() : this.element.find('.add-on .icon-th, .add-on .icon-time, .add-on .icon-calendar, .add-on .fa-calendar, .add-on .fa-clock-o').parent() : !1;
        this.componentReset = this.element.is('.date') ? 3 === this.bootcssVer ? this.element.find('.input-group-addon .glyphicon-remove, .input-group-addon .fa-times').parent() : this.element.find('.add-on .icon-remove, .add-on .fa-times').parent() : !1;
        this.hasInput = this.component && this.element.find('input').length;
        if (this.component && 0 === this.component.length) this.component = !1;
        this.linkField = options.linkField || this.element.data('link-field') || !1;
        this.linkFormat = DPGlobal.parseFormat(options.linkFormat || this.element.data('link-format') || DPGlobal.getDefaultFormat(this.formatType, 'link'), this.formatType);
        this.minuteStep = options.minuteStep || this.element.data('minute-step') || 5;
        this.pickerPosition = options.pickerPosition || this.element.data('picker-position') || 'bottom-right';
        this.showMeridian = options.showMeridian || this.element.data('show-meridian') || !1;
        this.initialDate = options.initialDate || new Date;
        this.zIndex = options.zIndex || this.element.data('z-index') || undefined;
        this.title = 'undefined' === typeof options.title ? !1 : options.title;
        this.timezone = options.timezone || timeZoneAbbreviation();
        this.icons = { leftArrow: this.fontAwesome ? 'fa-arrow-left' : 3 === this.bootcssVer ? 'glyphicon-arrow-left' : 'icon-arrow-left', rightArrow: this.fontAwesome ? 'fa-arrow-right' : 3 === this.bootcssVer ? 'glyphicon-arrow-right' : 'icon-arrow-right' };
        this.icontype = this.fontAwesome ? 'fa' : 'glyphicon';
        this._attachEvents();
        this.clickedOutside = function(e) { if (0 === $(e.target).closest('.datetimepicker').length) that.hide() };
        this.formatViewType = 'datetime';
        if ('formatViewType' in options) this.formatViewType = options.formatViewType;
        else if ('formatViewType' in this.element.data()) this.formatViewType = this.element.data('formatViewType');
        this.minView = 0;
        if ('minView' in options) this.minView = options.minView;
        else if ('minView' in this.element.data()) this.minView = this.element.data('min-view');
        this.minView = DPGlobal.convertViewMode(this.minView);
        this.maxView = DPGlobal.modes.length - 1;
        if ('maxView' in options) this.maxView = options.maxView;
        else if ('maxView' in this.element.data()) this.maxView = this.element.data('max-view');
        this.maxView = DPGlobal.convertViewMode(this.maxView);
        this.wheelViewModeNavigation = !1;
        if ('wheelViewModeNavigation' in options) this.wheelViewModeNavigation = options.wheelViewModeNavigation;
        else if ('wheelViewModeNavigation' in this.element.data()) this.wheelViewModeNavigation = this.element.data('view-mode-wheel-navigation');
        this.wheelViewModeNavigationInverseDirection = !1;
        if ('wheelViewModeNavigationInverseDirection' in options) this.wheelViewModeNavigationInverseDirection = options.wheelViewModeNavigationInverseDirection;
        else if ('wheelViewModeNavigationInverseDirection' in this.element.data()) this.wheelViewModeNavigationInverseDirection = this.element.data('view-mode-wheel-navigation-inverse-dir');
        this.wheelViewModeNavigationDelay = 100;
        if ('wheelViewModeNavigationDelay' in options) this.wheelViewModeNavigationDelay = options.wheelViewModeNavigationDelay;
        else if ('wheelViewModeNavigationDelay' in this.element.data()) this.wheelViewModeNavigationDelay = this.element.data('view-mode-wheel-navigation-delay');
        this.startViewMode = 2;
        if ('startView' in options) this.startViewMode = options.startView;
        else if ('startView' in this.element.data()) this.startViewMode = this.element.data('start-view');
        this.startViewMode = DPGlobal.convertViewMode(this.startViewMode);
        this.viewMode = this.startViewMode;
        this.viewSelect = this.minView;
        if ('viewSelect' in options) this.viewSelect = options.viewSelect;
        else if ('viewSelect' in this.element.data()) this.viewSelect = this.element.data('view-select');
        this.viewSelect = DPGlobal.convertViewMode(this.viewSelect);
        this.forceParse = !0;
        if ('forceParse' in options) this.forceParse = options.forceParse;
        else if ('dateForceParse' in this.element.data()) this.forceParse = this.element.data('date-force-parse');
        var template = 3 === this.bootcssVer ? DPGlobal.templateV3 : DPGlobal.template;
        while (-1 !== template.indexOf('{iconType}')) template = template.replace('{iconType}', this.icontype);
        while (-1 !== template.indexOf('{leftArrow}')) template = template.replace('{leftArrow}', this.icons.leftArrow);
        while (-1 !== template.indexOf('{rightArrow}')) template = template.replace('{rightArrow}', this.icons.rightArrow);
        this.picker = $(template).appendTo(this.isInline ? this.element : this.container).on({ click: $.proxy(this.click, this), mousedown: $.proxy(this.mousedown, this) });
        if (this.wheelViewModeNavigation)
            if ($.fn.mousewheel) this.picker.on({ mousewheel: $.proxy(this.mousewheel, this) });
            else console.log('Mouse Wheel event is not supported. Please include the jQuery Mouse Wheel plugin before enabling this option');
        if (this.isInline) this.picker.addClass('datetimepicker-inline');
        else this.picker.addClass('datetimepicker-dropdown-' + this.pickerPosition + ' dropdown-menu');
        if (this.isRTL) {
            this.picker.addClass('datetimepicker-rtl');
            var selector = 3 === this.bootcssVer ? '.prev span, .next span' : '.prev i, .next i';
            this.picker.find(selector).toggleClass(this.icons.leftArrow + ' ' + this.icons.rightArrow)
        }
        $(document).on('mousedown touchend', this.clickedOutside);
        this.autoclose = !1;
        if ('autoclose' in options) this.autoclose = options.autoclose;
        else if ('dateAutoclose' in this.element.data()) this.autoclose = this.element.data('date-autoclose');
        this.keyboardNavigation = !0;
        if ('keyboardNavigation' in options) this.keyboardNavigation = options.keyboardNavigation;
        else if ('dateKeyboardNavigation' in this.element.data()) this.keyboardNavigation = this.element.data('date-keyboard-navigation');
        this.todayBtn = options.todayBtn || this.element.data('date-today-btn') || !1;
        this.clearBtn = options.clearBtn || this.element.data('date-clear-btn') || !1;
        this.todayHighlight = options.todayHighlight || this.element.data('date-today-highlight') || !1;
        this.weekStart = 0;
        if ('undefined' !== typeof options.weekStart) this.weekStart = options.weekStart;
        else if ('undefined' !== typeof this.element.data('date-weekstart')) this.weekStart = this.element.data('date-weekstart');
        else if ('undefined' !== typeof dates[this.language].weekStart) this.weekStart = dates[this.language].weekStart;
        this.weekStart = this.weekStart % 7;
        this.weekEnd = (this.weekStart + 6) % 7;
        this.onRenderDay = function(date) { var render = (options.onRenderDay || function() { return [] })(date); if ('string' === typeof render) render = [render]; return ['day'].concat(render ? render : []) };
        this.onRenderHour = function(date) {
            var render = (options.onRenderHour || function() { return [] })(date),
                res;
            if ('string' === typeof render) render = [render];
            return ['hour'].concat(render ? render : [])
        };
        this.onRenderMinute = function(date) {
            var render = (options.onRenderMinute || function() { return [] })(date),
                res = ['minute'];
            if ('string' === typeof render) render = [render];
            if (date < this.startDate || date > this.endDate) res.push('disabled');
            else if (Math.floor(this.date.getUTCMinutes() / this.minuteStep) === Math.floor(date.getUTCMinutes() / this.minuteStep)) res.push('active');
            return res.concat(render ? render : [])
        };
        this.onRenderYear = function(date) {
            var render = (options.onRenderYear || function() { return [] })(date),
                res = ['year'];
            if ('string' === typeof render) render = [render];
            if (this.date.getUTCFullYear() === date.getUTCFullYear()) res.push('active');
            var currentYear = date.getUTCFullYear(),
                endYear = this.endDate.getUTCFullYear();
            if (date < this.startDate || currentYear > endYear) res.push('disabled');
            return res.concat(render ? render : [])
        };
        this.onRenderMonth = function(date) {
            var render = (options.onRenderMonth || function() { return [] })(date),
                res;
            if ('string' === typeof render) render = [render];
            return ['month'].concat(render ? render : [])
        };
        this.startDate = new Date(-8639968443048e3);
        this.endDate = new Date(8639968443048e3);
        this.datesDisabled = [];
        this.daysOfWeekDisabled = [];
        this.setStartDate(options.startDate || this.element.data('date-startdate'));
        this.setEndDate(options.endDate || this.element.data('date-enddate'));
        this.setDatesDisabled(options.datesDisabled || this.element.data('date-dates-disabled'));
        this.setDaysOfWeekDisabled(options.daysOfWeekDisabled || this.element.data('date-days-of-week-disabled'));
        this.setMinutesDisabled(options.minutesDisabled || this.element.data('date-minute-disabled'));
        this.setHoursDisabled(options.hoursDisabled || this.element.data('date-hour-disabled'));
        this.fillDow();
        this.fillMonths();
        this.update();
        this.showMode();
        if (this.isInline) this.show()
    };
    Datetimepicker.prototype = {
        constructor: Datetimepicker,
        _events: [],
        _attachEvents: function() {
            this._detachEvents();
            if (this.isInput) this._events = [
                [this.element, { focus: $.proxy(this.show, this), keyup: $.proxy(this.update, this), keydown: $.proxy(this.keydown, this) }]
            ];
            else if (this.component && this.hasInput) {
                this._events = [
                    [this.element.find('input'), { focus: $.proxy(this.show, this), keyup: $.proxy(this.update, this), keydown: $.proxy(this.keydown, this) }],
                    [this.component, { click: $.proxy(this.show, this) }]
                ];
                if (this.componentReset) this._events.push([this.componentReset, { click: $.proxy(this.reset, this) }])
            } else if (this.element.is('div')) this.isInline = !0;
            else this._events = [
                [this.element, { click: $.proxy(this.show, this) }]
            ];
            for (var i = 0, el, ev; i < this._events.length; i++) {
                el = this._events[i][0];
                ev = this._events[i][1];
                el.on(ev)
            }
        },
        _detachEvents: function() {
            for (var i = 0, el, ev; i < this._events.length; i++) {
                el = this._events[i][0];
                ev = this._events[i][1];
                el.off(ev)
            }
            this._events = []
        },
        show: function(e) {
            this.picker.show();
            this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
            if (this.forceParse) this.update();
            this.place();
            $(window).on('resize', $.proxy(this.place, this));
            if (e) {
                e.stopPropagation();
                e.preventDefault()
            }
            this.isVisible = !0;
            this.element.trigger({ type: 'show', date: this.date })
        },
        hide: function() {
            if (!this.isVisible) return;
            if (this.isInline) return;
            this.picker.hide();
            $(window).off('resize', this.place);
            this.viewMode = this.startViewMode;
            this.showMode();
            if (!this.isInput) $(document).off('mousedown', this.hide);
            if (this.forceParse && (this.isInput && this.element.val() || this.hasInput && this.element.find('input').val())) this.setValue();
            this.isVisible = !1;
            this.element.trigger({ type: 'hide', date: this.date })
        },
        remove: function() {
            this._detachEvents();
            $(document).off('mousedown', this.clickedOutside);
            this.picker.remove();
            delete this.picker;
            delete this.element.data().datetimepicker
        },
        getDate: function() { var d = this.getUTCDate(); if (null === d) return null; return new Date(d.getTime() + 6e4 * d.getTimezoneOffset()) },
        getUTCDate: function() { return this.date },
        getInitialDate: function() { return this.initialDate },
        setInitialDate: function(initialDate) { this.initialDate = initialDate },
        setDate: function(d) { this.setUTCDate(new Date(d.getTime() - 6e4 * d.getTimezoneOffset())) },
        setUTCDate: function(d) {
            if (d >= this.startDate && d <= this.endDate) {
                this.date = d;
                this.setValue();
                this.viewDate = this.date;
                this.fill()
            } else this.element.trigger({ type: 'outOfRange', date: d, startDate: this.startDate, endDate: this.endDate })
        },
        setFormat: function(format) {
            this.format = DPGlobal.parseFormat(format, this.formatType);
            var element;
            if (this.isInput) element = this.element;
            else if (this.component) element = this.element.find('input');
            if (element && element.val()) this.setValue()
        },
        setValue: function() {
            var formatted = this.getFormattedDate();
            if (!this.isInput) {
                if (this.component) this.element.find('input').val(formatted);
                this.element.data('date', formatted)
            } else this.element.val(formatted);
            if (this.linkField) $('#' + this.linkField).val(this.getFormattedDate(this.linkFormat))
        },
        getFormattedDate: function(format) { format = format || this.format; return DPGlobal.formatDate(this.date, format, this.language, this.formatType, this.timezone) },
        setStartDate: function(startDate) {
            this.startDate = startDate || this.startDate;
            if (8639968443048e3 !== this.startDate.valueOf()) this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language, this.formatType, this.timezone);
            this.update();
            this.updateNavArrows()
        },
        setEndDate: function(endDate) {
            this.endDate = endDate || this.endDate;
            if (8639968443048e3 !== this.endDate.valueOf()) this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language, this.formatType, this.timezone);
            this.update();
            this.updateNavArrows()
        },
        setDatesDisabled: function(datesDisabled) {
            this.datesDisabled = datesDisabled || [];
            if (!$.isArray(this.datesDisabled)) this.datesDisabled = this.datesDisabled.split(/,\s*/);
            var mThis = this;
            this.datesDisabled = $.map(this.datesDisabled, function(d) { return DPGlobal.parseDate(d, mThis.format, mThis.language, mThis.formatType, mThis.timezone).toDateString() });
            this.update();
            this.updateNavArrows()
        },
        setTitle: function(selector, value) { return this.picker.find(selector).find('th:eq(1)').text(!1 === this.title ? value : this.title) },
        setDaysOfWeekDisabled: function(daysOfWeekDisabled) {
            this.daysOfWeekDisabled = daysOfWeekDisabled || [];
            if (!$.isArray(this.daysOfWeekDisabled)) this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
            this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function(d) { return parseInt(d, 10) });
            this.update();
            this.updateNavArrows()
        },
        setMinutesDisabled: function(minutesDisabled) {
            this.minutesDisabled = minutesDisabled || [];
            if (!$.isArray(this.minutesDisabled)) this.minutesDisabled = this.minutesDisabled.split(/,\s*/);
            this.minutesDisabled = $.map(this.minutesDisabled, function(d) { return parseInt(d, 10) });
            this.update();
            this.updateNavArrows()
        },
        setHoursDisabled: function(hoursDisabled) {
            this.hoursDisabled = hoursDisabled || [];
            if (!$.isArray(this.hoursDisabled)) this.hoursDisabled = this.hoursDisabled.split(/,\s*/);
            this.hoursDisabled = $.map(this.hoursDisabled, function(d) { return parseInt(d, 10) });
            this.update();
            this.updateNavArrows()
        },
        place: function() {
            if (this.isInline) return;
            if (!this.zIndex) {
                var index_highest = 0;
                $('div').each(function() { var index_current = parseInt($(this).css('zIndex'), 10); if (index_current > index_highest) index_highest = index_current });
                this.zIndex = index_highest + 10
            }
            var offset, top, left, containerOffset;
            if (this.container instanceof $) containerOffset = this.container.offset();
            else containerOffset = $(this.container).offset();
            if (this.component) { left = (offset = this.component.offset()).left; if ('bottom-left' === this.pickerPosition || 'top-left' === this.pickerPosition) left += this.component.outerWidth() - this.picker.outerWidth() } else { left = (offset = this.element.offset()).left; if ('bottom-left' === this.pickerPosition || 'top-left' === this.pickerPosition) left += this.element.outerWidth() - this.picker.outerWidth() }
            var bodyWidth = document.body.clientWidth || window.innerWidth;
            if (left + 220 > bodyWidth) left = bodyWidth - 220;
            if ('top-left' === this.pickerPosition || 'top-right' === this.pickerPosition) top = offset.top - this.picker.outerHeight();
            else top = offset.top + this.height;
            top -= containerOffset.top;
            left -= containerOffset.left;
            this.picker.css({ top: top, left: left, zIndex: this.zIndex })
        },
        hour_minute: "^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]",
        update: function(argument_0) {
            var date, fromArgs = !1;
            if (arguments && arguments.length && ('string' === typeof argument_0 || argument_0 instanceof Date)) {
                date = argument_0;
                fromArgs = !0
            } else if ('string' === typeof(date = (this.isInput ? this.element.val() : this.element.find('input').val()) || this.element.data('date') || this.initialDate)) date = date.replace(/^\s+|\s+$/g, '');
            if (!date) {
                date = new Date;
                fromArgs = !1
            }
            if ("string" === typeof date)
                if (new RegExp(this.hour_minute).test(date) || new RegExp(this.hour_minute + ":[0-5][0-9]").test(date)) date = this.getDate();
            this.date = DPGlobal.parseDate(date, this.format, this.language, this.formatType, this.timezone);
            if (fromArgs) this.setValue();
            if (this.date < this.startDate) this.viewDate = new Date(this.startDate);
            else if (this.date > this.endDate) this.viewDate = new Date(this.endDate);
            else this.viewDate = new Date(this.date);
            this.fill()
        },
        fillDow: function() {
            var dowCnt = this.weekStart,
                html = '<tr>';
            while (dowCnt < this.weekStart + 7) html += '<th class="dow">' + dates[this.language].daysMin[dowCnt++ % 7] + '</th>';
            html += '</tr>';
            this.picker.find('.datetimepicker-days thead').append(html)
        },
        fillMonths: function() {
            for (var html = '', d = new Date(this.viewDate), i = 0; i < 12; i++) {
                d.setUTCMonth(i);
                html += '<span class="' + this.onRenderMonth(d).join(' ') + '">' + dates[this.language].monthsShort[i] + '</span>'
            }
            this.picker.find('.datetimepicker-months td').html(html)
        },
        fill: function() {
            if (!this.date || !this.viewDate) return;
            var d = new Date(this.viewDate),
                year = d.getUTCFullYear(),
                month = d.getUTCMonth(),
                dayMonth = d.getUTCDate(),
                hours = d.getUTCHours(),
                startYear = this.startDate.getUTCFullYear(),
                startMonth = this.startDate.getUTCMonth(),
                endYear = this.endDate.getUTCFullYear(),
                endMonth = this.endDate.getUTCMonth() + 1,
                currentDate = new UTCDate(this.date.getUTCFullYear(), this.date.getUTCMonth(), this.date.getUTCDate()).valueOf(),
                today = new Date;
            this.setTitle('.datetimepicker-days', dates[this.language].months[month] + ' ' + year);
            if ('time' === this.formatViewType) {
                var formatted = this.getFormattedDate();
                this.setTitle('.datetimepicker-hours', formatted);
                this.setTitle('.datetimepicker-minutes', formatted)
            } else {
                this.setTitle('.datetimepicker-hours', dayMonth + ' ' + dates[this.language].months[month] + ' ' + year);
                this.setTitle('.datetimepicker-minutes', dayMonth + ' ' + dates[this.language].months[month] + ' ' + year)
            }
            this.picker.find('tfoot th.today').text(dates[this.language].today || dates['en'].today).toggle(!1 !== this.todayBtn);
            this.picker.find('tfoot th.clear').text(dates[this.language].clear || dates['en'].clear).toggle(!1 !== this.clearBtn);
            this.updateNavArrows();
            this.fillMonths();
            var prevMonth = UTCDate(year, month - 1, 28, 0, 0, 0, 0),
                day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
            prevMonth.setUTCDate(day);
            prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7) % 7);
            var nextMonth = new Date(prevMonth);
            nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
            nextMonth = nextMonth.valueOf();
            var html = [],
                classes;
            while (prevMonth.valueOf() < nextMonth) {
                if (prevMonth.getUTCDay() === this.weekStart) html.push('<tr>');
                classes = this.onRenderDay(prevMonth);
                if (prevMonth.getUTCFullYear() < year || prevMonth.getUTCFullYear() === year && prevMonth.getUTCMonth() < month) classes.push('old');
                else if (prevMonth.getUTCFullYear() > year || prevMonth.getUTCFullYear() === year && prevMonth.getUTCMonth() > month) classes.push('new');
                if (this.todayHighlight && prevMonth.getUTCFullYear() === today.getFullYear() && prevMonth.getUTCMonth() === today.getMonth() && prevMonth.getUTCDate() === today.getDate()) classes.push('today');
                if (prevMonth.valueOf() === currentDate) classes.push('active');
                if (prevMonth.valueOf() + 864e5 <= this.startDate || prevMonth.valueOf() > this.endDate || -1 !== $.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) || -1 !== $.inArray(prevMonth.toDateString(), this.datesDisabled)) classes.push('disabled');
                html.push('<td class="' + classes.join(' ') + '">' + prevMonth.getUTCDate() + '</td>');
                if (prevMonth.getUTCDay() === this.weekEnd) html.push('</tr>');
                prevMonth.setUTCDate(prevMonth.getUTCDate() + 1)
            }
            this.picker.find('.datetimepicker-days tbody').empty().append(html.join(''));
            html = [];
            var txt = '',
                meridian = '',
                meridianOld = '',
                hoursDisabled = this.hoursDisabled || [];
            d = new Date(this.viewDate);
            for (var i = 0; i < 24; i++) {
                d.setUTCHours(i);
                classes = this.onRenderHour(d);
                if (-1 !== hoursDisabled.indexOf(i)) classes.push('disabled');
                var actual = UTCDate(year, month, dayMonth, i);
                if (actual.valueOf() + 36e5 <= this.startDate || actual.valueOf() > this.endDate) classes.push('disabled');
                else if (hours === i) classes.push('active');
                if (this.showMeridian && 2 === dates[this.language].meridiem.length) {
                    if ((meridian = i < 12 ? dates[this.language].meridiem[0] : dates[this.language].meridiem[1]) !== meridianOld) {
                        if ('' !== meridianOld) html.push('</fieldset>');
                        html.push('<fieldset class="hour"><legend>' + meridian.toUpperCase() + '</legend>')
                    }
                    meridianOld = meridian;
                    txt = i % 12 ? i % 12 : 12;
                    if (i < 12) classes.push('hour_am');
                    else classes.push('hour_pm');
                    html.push('<span class="' + classes.join(' ') + '">' + txt + '</span>');
                    if (23 === i) html.push('</fieldset>')
                } else {
                    txt = i + ':00';
                    html.push('<span class="' + classes.join(' ') + '">' + txt + '</span>')
                }
            }
            this.picker.find('.datetimepicker-hours td').html(html.join(''));
            html = [];
            meridianOld = meridian = txt = '';
            var minutesDisabled = this.minutesDisabled || [];
            d = new Date(this.viewDate);
            for (var i = 0; i < 60; i += this.minuteStep) {
                if (-1 !== minutesDisabled.indexOf(i)) continue;
                d.setUTCMinutes(i);
                d.setUTCSeconds(0);
                classes = this.onRenderMinute(d);
                if (this.showMeridian && 2 === dates[this.language].meridiem.length) {
                    if ((meridian = hours < 12 ? dates[this.language].meridiem[0] : dates[this.language].meridiem[1]) !== meridianOld) {
                        if ('' !== meridianOld) html.push('</fieldset>');
                        html.push('<fieldset class="minute"><legend>' + meridian.toUpperCase() + '</legend>')
                    }
                    meridianOld = meridian;
                    txt = hours % 12 ? hours % 12 : 12;
                    html.push('<span class="' + classes.join(' ') + '">' + txt + ':' + (i < 10 ? '0' + i : i) + '</span>');
                    if (59 === i) html.push('</fieldset>')
                } else {
                    txt = i + ':00';
                    html.push('<span class="' + classes.join(' ') + '">' + hours + ':' + (i < 10 ? '0' + i : i) + '</span>')
                }
            }
            this.picker.find('.datetimepicker-minutes td').html(html.join(''));
            var currentYear = this.date.getUTCFullYear(),
                months = this.setTitle('.datetimepicker-months', year).end().find('.month').removeClass('active');
            if (currentYear === year) months.eq(this.date.getUTCMonth()).addClass('active');
            if (year < startYear || year > endYear) months.addClass('disabled');
            if (year === startYear) months.slice(0, startMonth).addClass('disabled');
            if (year === endYear) months.slice(endMonth).addClass('disabled');
            html = '';
            year = 10 * parseInt(year / 10, 10);
            var yearCont = this.setTitle('.datetimepicker-years', year + '-' + (year + 9)).end().find('td');
            year -= 1;
            d = new Date(this.viewDate);
            for (var i = -1; i < 11; i++) {
                d.setUTCFullYear(year);
                classes = this.onRenderYear(d);
                if (-1 === i || 10 === i) classes.push(old);
                html += '<span class="' + classes.join(' ') + '">' + year + '</span>';
                year += 1
            }
            yearCont.html(html);
            this.place()
        },
        updateNavArrows: function() {
            var d = new Date(this.viewDate),
                year = d.getUTCFullYear(),
                month = d.getUTCMonth(),
                day = d.getUTCDate(),
                hour = d.getUTCHours();
            switch (this.viewMode) {
                case 0:
                    if (year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth() && day <= this.startDate.getUTCDate() && hour <= this.startDate.getUTCHours()) this.picker.find('.prev').css({ visibility: 'hidden' });
                    else this.picker.find('.prev').css({ visibility: 'visible' });
                    if (year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth() && day >= this.endDate.getUTCDate() && hour >= this.endDate.getUTCHours()) this.picker.find('.next').css({ visibility: 'hidden' });
                    else this.picker.find('.next').css({ visibility: 'visible' });
                    break;
                case 1:
                    if (year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth() && day <= this.startDate.getUTCDate()) this.picker.find('.prev').css({ visibility: 'hidden' });
                    else this.picker.find('.prev').css({ visibility: 'visible' });
                    if (year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth() && day >= this.endDate.getUTCDate()) this.picker.find('.next').css({ visibility: 'hidden' });
                    else this.picker.find('.next').css({ visibility: 'visible' });
                    break;
                case 2:
                    if (year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) this.picker.find('.prev').css({ visibility: 'hidden' });
                    else this.picker.find('.prev').css({ visibility: 'visible' });
                    if (year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) this.picker.find('.next').css({ visibility: 'hidden' });
                    else this.picker.find('.next').css({ visibility: 'visible' });
                    break;
                case 3:
                case 4:
                    if (year <= this.startDate.getUTCFullYear()) this.picker.find('.prev').css({ visibility: 'hidden' });
                    else this.picker.find('.prev').css({ visibility: 'visible' });
                    if (year >= this.endDate.getUTCFullYear()) this.picker.find('.next').css({ visibility: 'hidden' });
                    else this.picker.find('.next').css({ visibility: 'visible' });
                    break
            }
        },
        mousewheel: function(e) {
            e.preventDefault();
            e.stopPropagation();
            if (this.wheelPause) return;
            this.wheelPause = !0;
            var delta = e.originalEvent.wheelDelta,
                mode = delta > 0 ? 1 : 0 === delta ? 0 : -1;
            if (this.wheelViewModeNavigationInverseDirection) mode = -mode;
            this.showMode(mode);
            setTimeout($.proxy(function() { this.wheelPause = !1 }, this), this.wheelViewModeNavigationDelay)
        },
        click: function(e) {
            e.stopPropagation();
            e.preventDefault();
            var target = $(e.target).closest('span, td, th, legend');
            if (target.is('.' + this.icontype)) target = $(target).parent().closest('span, td, th, legend');
            if (1 === target.length) {
                if (target.is('.disabled')) { this.element.trigger({ type: 'outOfRange', date: this.viewDate, startDate: this.startDate, endDate: this.endDate }); return }
                switch (target[0].nodeName.toLowerCase()) {
                    case 'th':
                        switch (target[0].className) {
                            case 'switch':
                                this.showMode(1);
                                break;
                            case 'prev':
                            case 'next':
                                var dir = DPGlobal.modes[this.viewMode].navStep * ('prev' === target[0].className ? -1 : 1);
                                switch (this.viewMode) {
                                    case 0:
                                        this.viewDate = this.moveHour(this.viewDate, dir);
                                        break;
                                    case 1:
                                        this.viewDate = this.moveDate(this.viewDate, dir);
                                        break;
                                    case 2:
                                        this.viewDate = this.moveMonth(this.viewDate, dir);
                                        break;
                                    case 3:
                                    case 4:
                                        this.viewDate = this.moveYear(this.viewDate, dir);
                                        break
                                }
                                this.fill();
                                this.element.trigger({ type: target[0].className + ':' + this.convertViewModeText(this.viewMode), date: this.viewDate, startDate: this.startDate, endDate: this.endDate });
                                break;
                            case 'clear':
                                this.reset();
                                if (this.autoclose) this.hide();
                                break;
                            case 'today':
                                var date = new Date;
                                if ((date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0)) < this.startDate) date = this.startDate;
                                else if (date > this.endDate) date = this.endDate;
                                this.viewMode = this.startViewMode;
                                this.showMode(0);
                                this._setDate(date);
                                this.fill();
                                if (this.autoclose) this.hide();
                                break
                        }
                        break;
                    case 'span':
                        if (!target.is('.disabled')) {
                            var year = this.viewDate.getUTCFullYear(),
                                month = this.viewDate.getUTCMonth(),
                                day = this.viewDate.getUTCDate(),
                                hours = this.viewDate.getUTCHours(),
                                minutes = this.viewDate.getUTCMinutes(),
                                seconds = this.viewDate.getUTCSeconds();
                            if (target.is('.month')) {
                                this.viewDate.setUTCDate(1);
                                month = target.parent().find('span').index(target);
                                day = this.viewDate.getUTCDate();
                                this.viewDate.setUTCMonth(month);
                                this.element.trigger({ type: 'changeMonth', date: this.viewDate });
                                if (this.viewSelect >= 3) this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0))
                            } else if (target.is('.year')) {
                                this.viewDate.setUTCDate(1);
                                year = parseInt(target.text(), 10) || 0;
                                this.viewDate.setUTCFullYear(year);
                                this.element.trigger({ type: 'changeYear', date: this.viewDate });
                                if (this.viewSelect >= 4) this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0))
                            } else if (target.is('.hour')) {
                                hours = parseInt(target.text(), 10) || 0;
                                if (target.hasClass('hour_am') || target.hasClass('hour_pm'))
                                    if (12 === hours && target.hasClass('hour_am')) hours = 0;
                                    else if (12 !== hours && target.hasClass('hour_pm')) hours += 12;
                                this.viewDate.setUTCHours(hours);
                                this.element.trigger({ type: 'changeHour', date: this.viewDate });
                                if (this.viewSelect >= 1) this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0))
                            } else if (target.is('.minute')) {
                                minutes = parseInt(target.text().substr(target.text().indexOf(':') + 1), 10) || 0;
                                this.viewDate.setUTCMinutes(minutes);
                                this.element.trigger({ type: 'changeMinute', date: this.viewDate });
                                if (this.viewSelect >= 0) this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0))
                            }
                            if (0 !== this.viewMode) {
                                var oldViewMode = this.viewMode;
                                this.showMode(-1);
                                this.fill();
                                if (oldViewMode === this.viewMode && this.autoclose) this.hide()
                            } else { this.fill(); if (this.autoclose) this.hide() }
                        }
                        break;
                    case 'td':
                        if (target.is('.day') && !target.is('.disabled')) {
                            var day = parseInt(target.text(), 10) || 1,
                                year = this.viewDate.getUTCFullYear(),
                                month = this.viewDate.getUTCMonth(),
                                hours = this.viewDate.getUTCHours(),
                                minutes = this.viewDate.getUTCMinutes(),
                                seconds = this.viewDate.getUTCSeconds();
                            if (target.is('.old'))
                                if (0 === month) {
                                    month = 11;
                                    year -= 1
                                } else month -= 1;
                            else if (target.is('.new'))
                                if (11 === month) {
                                    month = 0;
                                    year += 1
                                } else month += 1;
                            this.viewDate.setUTCFullYear(year);
                            this.viewDate.setUTCMonth(month, day);
                            this.element.trigger({ type: 'changeDay', date: this.viewDate });
                            if (this.viewSelect >= 2) this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0))
                        }
                        var oldViewMode = this.viewMode;
                        this.showMode(-1);
                        this.fill();
                        if (oldViewMode === this.viewMode && this.autoclose) this.hide();
                        break
                }
            }
        },
        _setDate: function(date, which) {
            if (!which || 'date' === which) this.date = date;
            if (!which || 'view' === which) this.viewDate = date;
            this.fill();
            this.setValue();
            var element;
            if (this.isInput) element = this.element;
            else if (this.component) element = this.element.find('input');
            if (element) element.change();
            this.element.trigger({ type: 'changeDate', date: this.getDate() });
            if (null === date) this.date = this.viewDate
        },
        moveMinute: function(date, dir) {
            if (!dir) return date;
            var new_date = new Date(date.valueOf());
            new_date.setUTCMinutes(new_date.getUTCMinutes() + dir * this.minuteStep);
            return new_date
        },
        moveHour: function(date, dir) {
            if (!dir) return date;
            var new_date = new Date(date.valueOf());
            new_date.setUTCHours(new_date.getUTCHours() + dir);
            return new_date
        },
        moveDate: function(date, dir) {
            if (!dir) return date;
            var new_date = new Date(date.valueOf());
            new_date.setUTCDate(new_date.getUTCDate() + dir);
            return new_date
        },
        moveMonth: function(date, dir) {
            if (!dir) return date;
            var new_date = new Date(date.valueOf()),
                day = new_date.getUTCDate(),
                month = new_date.getUTCMonth(),
                mag = Math.abs(dir),
                new_month, test;
            dir = dir > 0 ? 1 : -1;
            if (1 === mag) {
                test = -1 === dir ? function() { return new_date.getUTCMonth() === month } : function() { return new_date.getUTCMonth() !== new_month };
                new_month = month + dir;
                new_date.setUTCMonth(new_month);
                if (new_month < 0 || new_month > 11) new_month = (new_month + 12) % 12
            } else {
                for (var i = 0; i < mag; i++) new_date = this.moveMonth(new_date, dir);
                new_month = new_date.getUTCMonth();
                new_date.setUTCDate(day);
                test = function() { return new_month !== new_date.getUTCMonth() }
            }
            while (test()) {
                new_date.setUTCDate(--day);
                new_date.setUTCMonth(new_month)
            }
            return new_date
        },
        moveYear: function(date, dir) { return this.moveMonth(date, 12 * dir) },
        dateWithinRange: function(date) { return date >= this.startDate && date <= this.endDate },
        keydown: function(e) {
            if (this.picker.is(':not(:visible)')) { if (27 === e.keyCode) this.show(); return }
            var dateChanged = !1,
                dir, newDate, newViewDate;
            switch (e.keyCode) {
                case 27:
                    this.hide();
                    e.preventDefault();
                    break;
                case 37:
                case 39:
                    if (!this.keyboardNavigation) break;
                    dir = 37 === e.keyCode ? -1 : 1;
                    var viewMode = this.viewMode;
                    if (e.ctrlKey) viewMode += 2;
                    else if (e.shiftKey) viewMode += 1;
                    if (4 === viewMode) {
                        newDate = this.moveYear(this.date, dir);
                        newViewDate = this.moveYear(this.viewDate, dir)
                    } else if (3 === viewMode) {
                        newDate = this.moveMonth(this.date, dir);
                        newViewDate = this.moveMonth(this.viewDate, dir)
                    } else if (2 === viewMode) {
                        newDate = this.moveDate(this.date, dir);
                        newViewDate = this.moveDate(this.viewDate, dir)
                    } else if (1 === viewMode) {
                        newDate = this.moveHour(this.date, dir);
                        newViewDate = this.moveHour(this.viewDate, dir)
                    } else if (0 === viewMode) {
                        newDate = this.moveMinute(this.date, dir);
                        newViewDate = this.moveMinute(this.viewDate, dir)
                    }
                    if (this.dateWithinRange(newDate)) {
                        this.date = newDate;
                        this.viewDate = newViewDate;
                        this.setValue();
                        this.update();
                        e.preventDefault();
                        dateChanged = !0
                    }
                    break;
                case 38:
                case 40:
                    if (!this.keyboardNavigation) break;
                    dir = 38 === e.keyCode ? -1 : 1;
                    viewMode = this.viewMode;
                    if (e.ctrlKey) viewMode += 2;
                    else if (e.shiftKey) viewMode += 1;
                    if (4 === viewMode) {
                        newDate = this.moveYear(this.date, dir);
                        newViewDate = this.moveYear(this.viewDate, dir)
                    } else if (3 === viewMode) {
                        newDate = this.moveMonth(this.date, dir);
                        newViewDate = this.moveMonth(this.viewDate, dir)
                    } else if (2 === viewMode) {
                        newDate = this.moveDate(this.date, 7 * dir);
                        newViewDate = this.moveDate(this.viewDate, 7 * dir)
                    } else if (1 === viewMode)
                        if (this.showMeridian) {
                            newDate = this.moveHour(this.date, 6 * dir);
                            newViewDate = this.moveHour(this.viewDate, 6 * dir)
                        } else {
                            newDate = this.moveHour(this.date, 4 * dir);
                            newViewDate = this.moveHour(this.viewDate, 4 * dir)
                        }
                    else if (0 === viewMode) {
                        newDate = this.moveMinute(this.date, 4 * dir);
                        newViewDate = this.moveMinute(this.viewDate, 4 * dir)
                    }
                    if (this.dateWithinRange(newDate)) {
                        this.date = newDate;
                        this.viewDate = newViewDate;
                        this.setValue();
                        this.update();
                        e.preventDefault();
                        dateChanged = !0
                    }
                    break;
                case 13:
                    if (0 !== this.viewMode) {
                        var oldViewMode = this.viewMode;
                        this.showMode(-1);
                        this.fill();
                        if (oldViewMode === this.viewMode && this.autoclose) this.hide()
                    } else { this.fill(); if (this.autoclose) this.hide() }
                    e.preventDefault();
                    break;
                case 9:
                    this.hide();
                    break
            }
            if (dateChanged) {
                var element;
                if (this.isInput) element = this.element;
                else if (this.component) element = this.element.find('input');
                if (element) element.change();
                this.element.trigger({ type: 'changeDate', date: this.getDate() })
            }
        },
        showMode: function(dir) {
            if (dir) {
                var newViewMode = Math.max(0, Math.min(DPGlobal.modes.length - 1, this.viewMode + dir));
                if (newViewMode >= this.minView && newViewMode <= this.maxView) {
                    this.element.trigger({ type: 'changeMode', date: this.viewDate, oldViewMode: this.viewMode, newViewMode: newViewMode });
                    this.viewMode = newViewMode
                }
            }
            this.picker.find('>div').hide().filter('.datetimepicker-' + DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
            this.updateNavArrows()
        },
        reset: function() { this._setDate(null, 'date') },
        convertViewModeText: function(viewMode) {
            switch (viewMode) {
                case 4:
                    return 'decade';
                case 3:
                    return 'year';
                case 2:
                    return 'month';
                case 1:
                    return 'day';
                case 0:
                    return 'hour'
            }
        }
    };
    var old = $.fn.datetimepicker;
    $.fn.datetimepicker = function(option) {
        var args = Array.apply(null, arguments),
            internal_return;
        args.shift();
        this.each(function() {
            var $this = $(this),
                data = $this.data('datetimepicker'),
                options = 'object' === typeof option && option;
            if (!data) $this.data('datetimepicker', data = new Datetimepicker(this, $.extend({}, $.fn.datetimepicker.defaults, options)));
            if ('string' === typeof option && 'function' === typeof data[option])
                if ((internal_return = data[option].apply(data, args)) !== undefined) return !1
        });
        if (internal_return !== undefined) return internal_return;
        else return this
    };
    $.fn.datetimepicker.defaults = {};
    $.fn.datetimepicker.Constructor = Datetimepicker;
    var dates = $.fn.datetimepicker.dates = { en: { days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'], months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], meridiem: ['am', 'pm'], suffix: ['st', 'nd', 'rd', 'th'], today: 'Today', clear: 'Clear' } },
        DPGlobal = {
            modes: [{ clsName: 'minutes', navFnc: 'Hours', navStep: 1 }, { clsName: 'hours', navFnc: 'Date', navStep: 1 }, { clsName: 'days', navFnc: 'Month', navStep: 1 }, { clsName: 'months', navFnc: 'FullYear', navStep: 1 }, { clsName: 'years', navFnc: 'FullYear', navStep: 10 }],
            isLeapYear: function(year) { return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0 },
            getDaysInMonth: function(year, month) { return [31, DPGlobal.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] },
            getDefaultFormat: function(type, field) {
                if ('standard' === type)
                    if ('input' === field) return 'yyyy-mm-dd hh:ii';
                    else return 'yyyy-mm-dd hh:ii:ss';
                else if ('php' === type)
                    if ('input' === field) return 'Y-m-d H:i';
                    else return 'Y-m-d H:i:s';
                else throw new Error('Invalid format type.')
            },
            validParts: function(type) {
                if ('standard' === type) return /t|hh?|HH?|p|P|z|Z|ii?|ss?|dd?|DD?|mm?|MM?|yy(?:yy)?/g;
                else if ('php' === type) return /[dDjlNwzFmMnStyYaABgGhHis]/g;
                else throw new Error('Invalid format type.')
            },
            nonpunctuation: /[^ -\/:-@\[-`{-~\t\n\rTZ]+/g,
            parseFormat: function(format, type) {
                var separators = format.replace(this.validParts(type), '\0').split('\0'),
                    parts = format.match(this.validParts(type));
                if (!separators || !separators.length || !parts || 0 === parts.length) throw new Error('Invalid date format.');
                return { separators: separators, parts: parts }
            },
            parseDate: function(date, format, language, type, timezone) {
                if (date instanceof Date) {
                    var dateUTC = new Date(date.valueOf() - 6e4 * date.getTimezoneOffset());
                    dateUTC.setMilliseconds(0);
                    return dateUTC
                }
                if (/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(date)) format = this.parseFormat('yyyy-mm-dd', type);
                if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}$/.test(date)) format = this.parseFormat('yyyy-mm-dd hh:ii', type);
                if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}\:\d{1,2}[Z]{0,1}$/.test(date)) format = this.parseFormat('yyyy-mm-dd hh:ii:ss', type);
                if (/^[-+]\d+[dmwy]([\s,]+[-+]\d+[dmwy])*$/.test(date)) {
                    var part_re = /([-+]\d+)([dmwy])/,
                        parts = date.match(/([-+]\d+)([dmwy])/g),
                        part, dir;
                    date = new Date;
                    for (var i = 0; i < parts.length; i++) {
                        part = part_re.exec(parts[i]);
                        dir = parseInt(part[1]);
                        switch (part[2]) {
                            case 'd':
                                date.setUTCDate(date.getUTCDate() + dir);
                                break;
                            case 'm':
                                date = Datetimepicker.prototype.moveMonth.call(Datetimepicker.prototype, date, dir);
                                break;
                            case 'w':
                                date.setUTCDate(date.getUTCDate() + 7 * dir);
                                break;
                            case 'y':
                                date = Datetimepicker.prototype.moveYear.call(Datetimepicker.prototype, date, dir);
                                break
                        }
                    }
                    return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), 0)
                }
                var parts = date && date.toString().match(this.nonpunctuation) || [],
                    date = new Date(0, 0, 0, 0, 0, 0, 0),
                    parsed = {},
                    setters_order = ['hh', 'h', 'ii', 'i', 'ss', 's', 'yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'D', 'DD', 'd', 'dd', 'H', 'HH', 'p', 'P', 'z', 'Z'],
                    setters_map = {
                        hh: function(d, v) { return d.setUTCHours(v) },
                        h: function(d, v) { return d.setUTCHours(v) },
                        HH: function(d, v) { return d.setUTCHours(12 === v ? 0 : v) },
                        H: function(d, v) { return d.setUTCHours(12 === v ? 0 : v) },
                        ii: function(d, v) { return d.setUTCMinutes(v) },
                        i: function(d, v) { return d.setUTCMinutes(v) },
                        ss: function(d, v) { return d.setUTCSeconds(v) },
                        s: function(d, v) { return d.setUTCSeconds(v) },
                        yyyy: function(d, v) { return d.setUTCFullYear(v) },
                        yy: function(d, v) { return d.setUTCFullYear(2e3 + v) },
                        m: function(d, v) {
                            v -= 1;
                            while (v < 0) v += 12;
                            v %= 12;
                            d.setUTCMonth(v);
                            while (d.getUTCMonth() !== v)
                                if (isNaN(d.getUTCMonth())) return d;
                                else d.setUTCDate(d.getUTCDate() - 1);
                            return d
                        },
                        d: function(d, v) { return d.setUTCDate(v) },
                        p: function(d, v) { return d.setUTCHours(1 === v ? d.getUTCHours() + 12 : d.getUTCHours()) },
                        z: function() { return timezone }
                    },
                    val, filtered, part;
                setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
                setters_map['dd'] = setters_map['d'];
                setters_map['P'] = setters_map['p'];
                setters_map['Z'] = setters_map['z'];
                date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
                if (parts.length === format.parts.length) {
                    for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
                        val = parseInt(parts[i], 10);
                        part = format.parts[i];
                        if (isNaN(val)) switch (part) {
                            case 'MM':
                                filtered = $(dates[language].months).filter(function() { var m = this.slice(0, parts[i].length); return m === parts[i].slice(0, m.length) });
                                val = $.inArray(filtered[0], dates[language].months) + 1;
                                break;
                            case 'M':
                                filtered = $(dates[language].monthsShort).filter(function() {
                                    var m = this.slice(0, parts[i].length),
                                        p = parts[i].slice(0, m.length);
                                    return m.toLowerCase() === p.toLowerCase()
                                });
                                val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
                                break;
                            case 'p':
                            case 'P':
                                val = $.inArray(parts[i].toLowerCase(), dates[language].meridiem);
                                break;
                            case 'z':
                            case 'Z':
                                timezone;
                                break
                        }
                        parsed[part] = val
                    }
                    for (var i = 0, s; i < setters_order.length; i++)
                        if ((s = setters_order[i]) in parsed && !isNaN(parsed[s])) setters_map[s](date, parsed[s])
                }
                return date
            },
            formatDate: function(date, format, language, type, timezone) {
                if (null === date) return '';
                var val;
                if ('standard' === type) {
                    val = { t: date.getTime(), yy: date.getUTCFullYear().toString().substring(2), yyyy: date.getUTCFullYear(), m: date.getUTCMonth() + 1, M: dates[language].monthsShort[date.getUTCMonth()], MM: dates[language].months[date.getUTCMonth()], d: date.getUTCDate(), D: dates[language].daysShort[date.getUTCDay()], DD: dates[language].days[date.getUTCDay()], p: 2 === dates[language].meridiem.length ? dates[language].meridiem[date.getUTCHours() < 12 ? 0 : 1] : '', h: date.getUTCHours(), i: date.getUTCMinutes(), s: date.getUTCSeconds(), z: timezone };
                    if (2 === dates[language].meridiem.length) val.H = val.h % 12 === 0 ? 12 : val.h % 12;
                    else val.H = val.h;
                    val.HH = (val.H < 10 ? '0' : '') + val.H;
                    val.P = val.p.toUpperCase();
                    val.Z = val.z;
                    val.hh = (val.h < 10 ? '0' : '') + val.h;
                    val.ii = (val.i < 10 ? '0' : '') + val.i;
                    val.ss = (val.s < 10 ? '0' : '') + val.s;
                    val.dd = (val.d < 10 ? '0' : '') + val.d;
                    val.mm = (val.m < 10 ? '0' : '') + val.m
                } else if ('php' === type) {
                    (val = { y: date.getUTCFullYear().toString().substring(2), Y: date.getUTCFullYear(), F: dates[language].months[date.getUTCMonth()], M: dates[language].monthsShort[date.getUTCMonth()], n: date.getUTCMonth() + 1, t: DPGlobal.getDaysInMonth(date.getUTCFullYear(), date.getUTCMonth()), j: date.getUTCDate(), l: dates[language].days[date.getUTCDay()], D: dates[language].daysShort[date.getUTCDay()], w: date.getUTCDay(), N: 0 === date.getUTCDay() ? 7 : date.getUTCDay(), S: date.getUTCDate() % 10 <= dates[language].suffix.length ? dates[language].suffix[date.getUTCDate() % 10 - 1] : '', a: 2 === dates[language].meridiem.length ? dates[language].meridiem[date.getUTCHours() < 12 ? 0 : 1] : '', g: date.getUTCHours() % 12 === 0 ? 12 : date.getUTCHours() % 12, G: date.getUTCHours(), i: date.getUTCMinutes(), s: date.getUTCSeconds() }).m = (val.n < 10 ? '0' : '') + val.n;
                    val.d = (val.j < 10 ? '0' : '') + val.j;
                    val.A = val.a.toString().toUpperCase();
                    val.h = (val.g < 10 ? '0' : '') + val.g;
                    val.H = (val.G < 10 ? '0' : '') + val.G;
                    val.i = (val.i < 10 ? '0' : '') + val.i;
                    val.s = (val.s < 10 ? '0' : '') + val.s
                } else throw new Error('Invalid format type.');
                for (var date = [], seps = $.extend([], format.separators), i = 0, cnt = format.parts.length; i < cnt; i++) {
                    if (seps.length) date.push(seps.shift());
                    date.push(val[format.parts[i]])
                }
                if (seps.length) date.push(seps.shift());
                return date.join('')
            },
            convertViewMode: function(viewMode) {
                switch (viewMode) {
                    case 4:
                    case 'decade':
                        viewMode = 4;
                        break;
                    case 3:
                    case 'year':
                        viewMode = 3;
                        break;
                    case 2:
                    case 'month':
                        viewMode = 2;
                        break;
                    case 1:
                    case 'day':
                        viewMode = 1;
                        break;
                    case 0:
                    case 'hour':
                        viewMode = 0;
                        break
                }
                return viewMode
            },
            headTemplate: '<thead>' + '<tr>' + '<th class="prev"><i class="{iconType} {leftArrow}"/></th>' + '<th colspan="5" class="switch"></th>' + '<th class="next"><i class="{iconType} {rightArrow}"/></th>' + '</tr>' + '</thead>',
            headTemplateV3: '<thead>' + '<tr>' + '<th class="prev"><span class="{iconType} {leftArrow}"></span> </th>' + '<th colspan="5" class="switch"></th>' + '<th class="next"><span class="{iconType} {rightArrow}"></span> </th>' + '</tr>' + '</thead>',
            contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
            footTemplate: '<tfoot>' + '<tr><th colspan="7" class="today"></th></tr>' + '<tr><th colspan="7" class="clear"></th></tr>' + '</tfoot>'
        };
    DPGlobal.template = '<div class="datetimepicker">' + '<div class="datetimepicker-minutes">' + '<table class=" table-condensed">' + DPGlobal.headTemplate + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-hours">' + '<table class=" table-condensed">' + DPGlobal.headTemplate + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-days">' + '<table class=" table-condensed">' + DPGlobal.headTemplate + '<tbody></tbody>' + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-months">' + '<table class="table-condensed">' + DPGlobal.headTemplate + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-years">' + '<table class="table-condensed">' + DPGlobal.headTemplate + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '</div>';
    DPGlobal.templateV3 = '<div class="datetimepicker">' + '<div class="datetimepicker-minutes">' + '<table class=" table-condensed">' + DPGlobal.headTemplateV3 + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-hours">' + '<table class=" table-condensed">' + DPGlobal.headTemplateV3 + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-days">' + '<table class=" table-condensed">' + DPGlobal.headTemplateV3 + '<tbody></tbody>' + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-months">' + '<table class="table-condensed">' + DPGlobal.headTemplateV3 + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '<div class="datetimepicker-years">' + '<table class="table-condensed">' + DPGlobal.headTemplateV3 + DPGlobal.contTemplate + DPGlobal.footTemplate + '</table>' + '</div>' + '</div>';
    $.fn.datetimepicker.DPGlobal = DPGlobal;
    $.fn.datetimepicker.noConflict = function() { $.fn.datetimepicker = old; return this };
    $(document).on('focus.datetimepicker.data-api click.datetimepicker.data-api', '[data-provide="datetimepicker"]', function(e) {
        var $this = $(this);
        if ($this.data('datetimepicker')) return;
        e.preventDefault();
        $this.datetimepicker('show')
    });
    $(function() { $('[data-provide="datetimepicker-inline"]').datetimepicker() })
});
$.fn.datetimepicker.dates.cn = { days: ['日', '一', '二', '三', '四', '五', '六', '日'], daysShort: ['日', '一', '二', '三', '四', '五', '六', '日'], daysMin: ['日', '一', '二', '三', '四', '五', '六', '日'], months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], monthsShort: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], meridiem: ['am', 'pm'], suffix: ['st', 'nd', 'rd', 'th'], today: '今天', clear: '清除' };
! function() {
    function r(e, n, t) {
        function o(i, f) {
            if (!n[i]) {
                if (!e[i]) { var c = "function" == typeof require && require; if (!f && c) return c(i, !0); if (u) return u(i, !0); var a = new Error("Cannot find module '" + i + "'"); throw a.code = "MODULE_NOT_FOUND", a }
                var p = n[i] = { exports: {} };
                e[i][0].call(p.exports, function(r) { var n; return o(e[i][1][r] || r) }, p, p.exports, r, e, n, t)
            }
            return n[i].exports
        }
        for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
        return o
    }
    return r
}()({
    1: [function(require, module, exports) {
        ! function(root, factory) {
            if ('function' === typeof define && define.amd) define([], factory);
            else if ('object' === typeof exports) module.exports = factory();
            else root.List = factory()
        }(this, function() {
            var List = function(container, data, config, callbacks) {
                this.$container = container instanceof $ ? container : $(container);
                this.data = [];
                if (data) this.data = $.extend(!0, this.data, data);
                this.config = { type: 'list', tableHeader: [], item: config.item || window.Item };
                if (config) this.config = $.extend(!0, this.config, config);
                this.callbacks = {};
                if (callbacks) this.callbacks = $.extend(!0, this.callbacks, callbacks);
                this.loading = !1;
                this.Init()
            };
            List.prototype = {
                Init: function() {
                    var self = this;
                    this.HTML = 'table' == this.config.type ? '<table class="' + (this.config.table_class || 'table') + '"><colgroup>' + this._initTableCol() + '</colgroup><thead><tr>' + this._initTableHeader() + '</tr></thead><tbody><tr><td class="loading" colspan="' + this.config.tableHeader.length + '">数据加载中</td></tr></tbody></table>' : '<ul class="list-group"><li class="no-data loading">数据加载中</li></ul>';
                    this.$el = $(this.HTML).appendTo(this.$container);
                    this.$itemWrap = 'table' == this.config.type ? this.$el.find('tbody') : this.$el;
                    this.$loading = this.$el.find('.loading');
                    this.listObj = [];
                    if (this.data.length > 0) this._bindData(this.data)
                },
                _initTableCol: function() {
                    var str = '';
                    if (this.config.tableHeader.length > 0)
                        for (var k = this.config.tableHeader.length, i = 0; i < k; i++) str = str + '<col width="' + (this.config.tableHeader[i]['width'] || '') + '">';
                    return str
                },
                _initTableHeader: function() {
                    var str = '';
                    if (this.config.tableHeader.length > 0)
                        for (var k = this.config.tableHeader.length, i = 0; i < k; i++) str = str + '<th>' + (this.config.tableHeader[i]['txt'] || '') + '</th>';
                    return str
                },
                _bindData: function(data) {
                    if (1 == this.loading) return !1;
                    if (data.length > 0) {
                        for (var k = Math.min(this.config.size, data.length), i = 0; i < k; i++)
                            if (this.listObj[i]) this.listObj[i].UpdateData(data[i]);
                            else if (this.config.item) this.listObj[i] = new this.config.item(this.$itemWrap, data[i], this.config, this.callbacks)
                    } else this.$itemWrap.html('table' == this.config.type ? '<tr><td class="loading" colspan="' + this.config.tableHeader.length + '">暂无数据</td></tr>' : '<li class="no-data">暂无数据</li>')
                },
                _clear: function(callback) {
                    for (var o in this.listObj) {
                        this.listObj[o].Clear();
                        delete this.listObj[o]
                    }
                    this.listObj = [];
                    this.$itemWrap.empty();
                    if ('function' == typeof callback) callback()
                },
                UpdateData: function(data, needUpdate) {
                    this.loading = !1;
                    this.$loading.hide();
                    if (data) {
                        var needClear = this.data.length !== data.length || needUpdate;
                        this.data = data;
                        this._clear();
                        this._bindData(this.data)
                    }
                },
                SetContent: function(str) {
                    this.loading = !0;
                    this.$loading.show()
                }
            };
            return List
        })
    }, {}],
    2: [function(require, module, exports) {
        ! function(root, factory) {
            if ('function' === typeof define && define.amd) define([], factory);
            else if ('object' === typeof exports) module.exports = factory();
            else root.TableItem = factory()
        }(this, function() {
            var TableItem = function(container, data, config, callbacks) {
                this.$container = container instanceof $ ? container : $(container);
                this.data = [];
                if (data) this.data = data;
                this.config = {};
                if (config) this.config = $.extend(!0, this.config, config);
                this.callbacks = {};
                if (callbacks) this.callbacks = $.extend(!0, this.callbacks, callbacks);
                this.obj = {};
                if (this.data) this.Init()
            };

            function arrayToHTML(arr) {
                for (var str = [], i = 0, len = arr.length; i < len; i++) {
                    var item = arr[i];
                    if ('object' == typeof item && item.txt) str.push('<td><a href="javascript:void(0);" class="operation" data-id="' + (item.id || 0) + '">' + item.txt + '</a></td>');
                    else str.push('<td>' + item + '</td>')
                }
                return str.join('')
            }
            TableItem.prototype = {
                Init: function() {
                    var self = this,
                        tgt = null,
                        data = this.data,
                        tdHtml;
                    if (-1 == this._createTd().indexOf('disabled-permission')) var HTML = '<tr>' + this._createTd() + '</tr>';
                    else var HTML = '<tr class="disabled-permission">' + this._createTd() + '</tr>';
                    this.obj.$el = $(HTML).appendTo(this.$container);
                    this.obj.$el.parent().children('.disabled-permission').attr('title', '无该应用管理权限，请联系团队管理员添加');
                    this.obj.$el.bind('click', function(e) {
                        var tgt = $(e.target);
                        if (tgt.hasClass('operation') && !tgt.hasClass('disabled-permission'))
                            if ('function' == typeof self.callbacks.onClick) self.callbacks.onClick(tgt.data())
                    })
                },
                _createTd: function() {
                    var str = '',
                        data;
                    return arrayToHTML(this.data)
                },
                _clear: function() {
                    this.obj.$el.remove();
                    for (var o in this.obj)
                        if ('Clear' !== o) {
                            this.obj[o] = null;
                            delete this.obj[o]
                        }
                },
                UpdateData: function(data) {
                    this.data = $.extend(!0, this.data, data);
                    this.obj.$el.empty();
                    this.obj.$el.html(arrayToHTML(data))
                },
                Clear: function() { this._clear() }
            };
            return TableItem
        })
    }, {}],
    3: [function(require, module, exports) {
        var tableItem = require('../../../components/table_item/scripts/table_item'),
            List = require('../../../components/list/scripts/list'),
            Pagination = require('../../../vendor/scripts/jquery.simplePagination');
        ! function(root, factory) {
            if ('function' === typeof define && define.amd) define([], factory);
            else if ('object' === typeof exports) module.exports = factory();
            else root.returnExports = factory()
        }(this, function() {
            var pageSize = 10,
                loadingMask = $('.loading-shadow');

            function formatDate(date) {
                var y = date.getFullYear(),
                    m = date.getMonth() + 1,
                    d = date.getDate();
                if (m < 10) m = '0' + m;
                if (d < 10) d = '0' + d;
                return y + '-' + m + '-' + d
            }

            function getRecentDate(n) {
                var start = new Date,
                    end = new Date,
                    oneDay = 24 * 3600 * 1e3;
                start.setTime(start.getTime() - oneDay * n);
                end.setTime(end.getTime() - oneDay);
                return { start: formatDate(start), end: formatDate(end) }
            }

            function checkInputDate(start, end, tempField) {
                var startD = new Date(start),
                    endD = new Date(end),
                    minD = new Date(getRecentDate(180).start);
                if (startD > endD) { alert('开始日期不能大于结束日期'); return !1 }
                if (startD < minD) { alert('仅提供最近180天的数据，请选择有效的时间段'); return !1 }
                return !0
            }

            function createPager(total) {
                var self = this;
                if (this.pagerCOM) return;
                this.pagerCOM = this.pagerContainer.pagination({
                    pages: total,
                    hrefTextPrefix: window.location.hash + '|',
                    onPageClick: function(page, e) {
                        if (e) e.preventDefault();
                        self.getData(page, queryStartDate, queryEndDate)
                    }
                })
            }

            function resetPager() {
                if (this.pagerCOM) {
                    this.pagerCOM.pagination('destroy');
                    this.pagerCOM = null
                }
            }

            function createTableCOM() { this.tableCOM = new List(this.tableContainer, [], { size: pageSize, item: tableItem, tableHeader: [{ txt: '序号', width: '10%' }, { txt: '价格<span class="unit"> (元)</span>', width: '10%' }, { txt: '作品名称', width: '30%' }, { txt: '销量', width: '20%' }, { txt: '销售额<span class="unit"> (元)</span>', width: '30%' }], type: 'table' }, { onClick: function(data) { console.log(data) } }) }

            function ajaxAPI(page, type, start, end, callback) {
                loadingMask.show();
                $.ajax({ dataType: 'json', type: "get", url: '/theme/data/sales.json', data: { page: page, source_type: type, size: pageSize, start_date: start, end_date: end }, success: callback, complete: function(e) { loadingMask.hide() } })
            }

            function formatTableRow(curPage, listData) {
                for (var arr = [], i = 0; i < listData.length; i++) {
                    var item = listData[i];
                    arr.push([i + 1 + (curPage - 1) * pageSize, item.price, item.name, item.sales_num ? item.sales_num : '0', item.sales_amount ? item.sales_amount : '0'])
                }
                return arr
            }

            function disableBtn(btn) {
                btn.addClass('disabled');
                var n = 10;
                btn.text('导出(' + n + ')');

                function timeCount() {
                    n--;
                    btn.text('导出(' + n + ')');
                    if (n > 0) setTimeout(timeCount, 1e3);
                    else btn.removeClass('disabled').text('导出')
                }
                setTimeout(timeCount, 1e3)
            }

            function exportData(type, start, end) {
                var p = { source_type: type, start_date: start, end_date: end };
                window.open(location.origin + '/theme/data/export-sales-list?' + $.param(p))
            }

            function tableView(cfg) {
                this.rootEl = $(cfg.el);
                this.tableContainer = this.rootEl.find('.content');
                this.tableCOM = null;
                this.pagerContainer = this.rootEl.find('.pagination-wrap');
                this.pagerCOM = null;
                this.createPager = createPager;
                this.createTableCOM = createTableCOM;
                this.resetPager = resetPager;
                this.getData = cfg.getData;
                this.onloadData = cfg.onloadData
            }

            function responseData(res) {
                if (0 === res.errno) {
                    this.rootEl.find('.count').html(res.data.total_num);
                    this.rootEl.find('.amount').html(res.data.total_amount);
                    var listData = res.data.rows,
                        totalPage = Math.ceil(res.data.total / pageSize);
                    this.tableCOM.UpdateData(formatTableRow(this.curPage, listData));
                    this.createPager(totalPage)
                } else this.tableCOM.UpdateData([])
            }
            var last7Day = getRecentDate(7),
                queryStartDate = last7Day.start,
                queryEndDate = last7Day.end,
                typeMap_theme = 1,
                typeMap_font = 2,
                typeMap_wallpaper = 3,
                dataDiv = $('#allSalesData'),
                switchTabs = $('ul.nav-tabs li', dataDiv),
                dateInput = $('.date-wrap input.date', dataDiv);
            dateInput.eq(0).val(queryStartDate);
            dateInput.eq(1).val(queryEndDate);
            dateInput.datetimepicker({ language: 'cn', format: 'yyyy-mm-dd', minView: 'month', autoclose: !0 });
            $('.query-btn', dataDiv).on('click', function() {
                if (!checkInputDate(dateInput.eq(0).val(), dateInput.eq(1).val())) return;
                queryStartDate = dateInput.eq(0).val();
                queryEndDate = dateInput.eq(1).val();
                dataViewTheme.resetPager();
                dataViewFont.resetPager();
                dataViewWallpaper.resetPager();
                dataViewTheme.getData(1, queryStartDate, queryEndDate);
                dataViewFont.getData(1, queryStartDate, queryEndDate);
                dataViewWallpaper.getData(1, queryStartDate, queryEndDate)
            });
            $('.export-btn', dataDiv).on('click', function() {
                var btn = $(this);
                if (btn.hasClass('disabled')) return;
                var start = dateInput.eq(0).val(),
                    end = dateInput.eq(1).val();
                if (!checkInputDate(start, end)) return;
                exportData(dataDiv.find('.nav-tabs li.active').attr('sourcetype'), start, end);
                disableBtn(btn)
            });
            var dataViewTheme = new tableView({
                el: $('#dataViewTheme'),
                getData: function(page, start, end) {
                    var self = this;
                    ajaxAPI(this.curPage = page, typeMap_theme, start, end, function(d) { self.onloadData(d) })
                },
                onloadData: responseData
            });
            dataViewTheme.createTableCOM();
            dataViewTheme.getData(1, last7Day.start, last7Day.end);
            var dataViewFont = new tableView({
                el: $('#dataViewFont'),
                getData: function(page, start, end) {
                    var self = this;
                    ajaxAPI(this.curPage = page, typeMap_font, start, end, function(d) { self.onloadData(d) })
                },
                onloadData: responseData
            });
            dataViewFont.createTableCOM();
            dataViewFont.getData(1, last7Day.start, last7Day.end);
            var dataViewWallpaper = new tableView({
                el: $('#dataViewWallpaper'),
                getData: function(page, start, end) {
                    var self = this;
                    ajaxAPI(this.curPage = page, typeMap_wallpaper, start, end, function(d) { self.onloadData(d) })
                },
                onloadData: responseData
            });
            dataViewWallpaper.createTableCOM();
            dataViewWallpaper.getData(1, last7Day.start, last7Day.end)
        })
    }, { "../../../components/list/scripts/list": 1, "../../../components/table_item/scripts/table_item": 2, "../../../vendor/scripts/jquery.simplePagination": 4 }],
    4: [function(require, module, exports) {
        $ = jQuery, methods = {
            init: function(options) {
                var o = $.extend({ items: 1, itemsOnPage: 1, pages: 0, displayedPages: 5, edges: 2, currentPage: 0, useAnchors: !0, hrefTextPrefix: '#page-', hrefTextSuffix: '', prevText: 'Prev', nextText: 'Next', ellipseText: '&hellip;', ellipsePageSet: !0, cssStyle: 'light-theme', listStyle: '', labelMap: [], selectOnClick: !0, nextAtFront: !1, invertPageOrder: !1, useStartEdge: !0, useEndEdge: !0, onPageClick: function(pageNumber, event) {}, onInit: function() {} }, options || {}),
                    self = this;
                o.pages = o.pages ? o.pages : Math.ceil(o.items / o.itemsOnPage) ? Math.ceil(o.items / o.itemsOnPage) : 1;
                if (o.currentPage) o.currentPage = o.currentPage - 1;
                else o.currentPage = !o.invertPageOrder ? 0 : o.pages - 1;
                o.halfDisplayed = o.displayedPages / 2;
                this.each(function() {
                    self.addClass(o.cssStyle + ' simple-pagination').data('pagination', o);
                    methods._draw.call(self)
                });
                o.onInit();
                return this
            },
            selectPage: function(page) { methods._selectPage.call(this, page - 1); return this },
            prevPage: function() { var o = this.data('pagination'); if (!o.invertPageOrder) { if (o.currentPage > 0) methods._selectPage.call(this, o.currentPage - 1) } else if (o.currentPage < o.pages - 1) methods._selectPage.call(this, o.currentPage + 1); return this },
            nextPage: function() { var o = this.data('pagination'); if (!o.invertPageOrder) { if (o.currentPage < o.pages - 1) methods._selectPage.call(this, o.currentPage + 1) } else if (o.currentPage > 0) methods._selectPage.call(this, o.currentPage - 1); return this },
            getPagesCount: function() { return this.data('pagination').pages },
            setPagesCount: function(count) { this.data('pagination').pages = count },
            getCurrentPage: function() { return this.data('pagination').currentPage + 1 },
            destroy: function() { this.empty(); return this },
            drawPage: function(page) {
                var o = this.data('pagination');
                o.currentPage = page - 1;
                this.data('pagination', o);
                methods._draw.call(this);
                return this
            },
            redraw: function() { methods._draw.call(this); return this },
            disable: function() {
                var o = this.data('pagination');
                o.disabled = !0;
                this.data('pagination', o);
                methods._draw.call(this);
                return this
            },
            enable: function() {
                var o = this.data('pagination');
                o.disabled = !1;
                this.data('pagination', o);
                methods._draw.call(this);
                return this
            },
            updateItems: function(newItems) {
                var o = this.data('pagination');
                o.items = newItems;
                o.pages = methods._getPages(o);
                this.data('pagination', o);
                methods._draw.call(this)
            },
            updateItemsOnPage: function(itemsOnPage) {
                var o = this.data('pagination');
                o.itemsOnPage = itemsOnPage;
                o.pages = methods._getPages(o);
                this.data('pagination', o);
                methods._selectPage.call(this, 0);
                return this
            },
            getItemsOnPage: function() { return this.data('pagination').itemsOnPage },
            _draw: function() {
                var o = this.data('pagination'),
                    interval = methods._getInterval(o),
                    i, tagName;
                methods.destroy.call(this);
                var $panel = 'UL' === (tagName = 'function' === typeof this.prop ? this.prop('tagName') : this.attr('tagName')) ? this : $('<ul' + (o.listStyle ? ' class="' + o.listStyle + '"' : '') + '></ul>').appendTo(this);
                if (o.prevText) methods._appendItem.call(this, !o.invertPageOrder ? o.currentPage - 1 : o.currentPage + 1, { text: o.prevText, classes: 'prev' });
                if (o.nextText && o.nextAtFront) methods._appendItem.call(this, !o.invertPageOrder ? o.currentPage + 1 : o.currentPage - 1, { text: o.nextText, classes: 'next' });
                if (!o.invertPageOrder) {
                    if (interval.start > 0 && o.edges > 0) {
                        if (o.useStartEdge) { var end = Math.min(o.edges, interval.start); for (i = 0; i < end; i++) methods._appendItem.call(this, i) }
                        if (o.edges < interval.start && interval.start - o.edges != 1) $panel.append('<li class="disabled"><span class="ellipse">' + o.ellipseText + '</span></li>');
                        else if (interval.start - o.edges == 1) methods._appendItem.call(this, o.edges)
                    }
                } else if (interval.end < o.pages && o.edges > 0) {
                    if (o.useStartEdge) { var begin = Math.max(o.pages - o.edges, interval.end); for (i = o.pages - 1; i >= begin; i--) methods._appendItem.call(this, i) }
                    if (o.pages - o.edges > interval.end && o.pages - o.edges - interval.end != 1) $panel.append('<li class="disabled"><span class="ellipse">' + o.ellipseText + '</span></li>');
                    else if (o.pages - o.edges - interval.end == 1) methods._appendItem.call(this, interval.end)
                }
                if (!o.invertPageOrder)
                    for (i = interval.start; i < interval.end; i++) methods._appendItem.call(this, i);
                else
                    for (i = interval.end - 1; i >= interval.start; i--) methods._appendItem.call(this, i);
                if (!o.invertPageOrder) {
                    if (interval.end < o.pages && o.edges > 0) {
                        if (o.pages - o.edges > interval.end && o.pages - o.edges - interval.end != 1) $panel.append('<li class="disabled"><span class="ellipse">' + o.ellipseText + '</span></li>');
                        else if (o.pages - o.edges - interval.end == 1) methods._appendItem.call(this, interval.end);
                        if (o.useEndEdge) { var begin; for (i = begin = Math.max(o.pages - o.edges, interval.end); i < o.pages; i++) methods._appendItem.call(this, i) }
                    }
                } else if (interval.start > 0 && o.edges > 0) {
                    if (o.edges < interval.start && interval.start - o.edges != 1) $panel.append('<li class="disabled"><span class="ellipse">' + o.ellipseText + '</span></li>');
                    else if (interval.start - o.edges == 1) methods._appendItem.call(this, o.edges);
                    if (o.useEndEdge) { var end; for (i = (end = Math.min(o.edges, interval.start)) - 1; i >= 0; i--) methods._appendItem.call(this, i) }
                }
                if (o.nextText && !o.nextAtFront) methods._appendItem.call(this, !o.invertPageOrder ? o.currentPage + 1 : o.currentPage - 1, { text: o.nextText, classes: 'next' });
                if (o.ellipsePageSet && !o.disabled) methods._ellipseClick.call(this, $panel)
            },
            _getPages: function(o) { var pages; return Math.ceil(o.items / o.itemsOnPage) || 1 },
            _getInterval: function(o) { return { start: Math.ceil(o.currentPage > o.halfDisplayed ? Math.max(Math.min(o.currentPage - o.halfDisplayed, o.pages - o.displayedPages), 0) : 0), end: Math.ceil(o.currentPage > o.halfDisplayed ? Math.min(o.currentPage + o.halfDisplayed, o.pages) : Math.min(o.displayedPages, o.pages)) } },
            _appendItem: function(pageIndex, opts) {
                var self = this,
                    options, $link, o = self.data('pagination'),
                    $linkWrapper = $('<li></li>'),
                    $ul = self.find('ul');
                options = { text: (pageIndex = pageIndex < 0 ? 0 : pageIndex < o.pages ? pageIndex : o.pages - 1) + 1, classes: '' };
                if (o.labelMap.length && o.labelMap[pageIndex]) options.text = o.labelMap[pageIndex];
                options = $.extend(options, opts || {});
                if (pageIndex == o.currentPage || o.disabled) {
                    if (o.disabled || 'prev' === options.classes || 'next' === options.classes) $linkWrapper.addClass('disabled');
                    else $linkWrapper.addClass('active');
                    $link = $('<span class="current">' + options.text + '</span>')
                } else {
                    if (o.useAnchors) $link = $('<a href="' + o.hrefTextPrefix + (pageIndex + 1) + o.hrefTextSuffix + '" class="page-link">' + options.text + '</a>');
                    else $link = $('<span >' + options.text + '</span>');
                    $link.click(function(event) { return methods._selectPage.call(self, pageIndex, event) })
                }
                if (options.classes) $link.addClass(options.classes);
                $linkWrapper.append($link);
                if ($ul.length) $ul.append($linkWrapper);
                else self.append($linkWrapper)
            },
            _selectPage: function(pageIndex, event) {
                var o = this.data('pagination');
                o.currentPage = pageIndex;
                if (o.selectOnClick) methods._draw.call(this);
                return o.onPageClick(pageIndex + 1, event)
            },
            _ellipseClick: function($panel) {
                var self = this,
                    o = this.data('pagination'),
                    $ellip = $panel.find('.ellipse');
                $ellip.addClass('clickable').parent().removeClass('disabled');
                $ellip.click(function(event) {
                    if (!o.disable) {
                        var $this = $(this),
                            val = (parseInt($this.parent().prev().text(), 10) || 0) + 1;
                        $this.html('<input type="number" min="1" max="' + o.pages + '" step="1" value="' + val + '">').find('input').focus().click(function(event) { event.stopPropagation() }).keyup(function(event) { var val = $(this).val(); if (13 === event.which && '' !== val) { if (val > 0 && val <= o.pages) methods._selectPage.call(self, val - 1) } else if (27 === event.which) $ellip.empty().html(o.ellipseText) }).bind('blur', function(event) {
                            var val = $(this).val();
                            if ('' !== val) methods._selectPage.call(self, val - 1);
                            $ellip.empty().html(o.ellipseText);
                            return !1
                        })
                    }
                    return !1
                })
            }
        }, void($.fn.pagination = function(method) {
            if (methods[method] && '_' != method.charAt(0)) return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
            else if ('object' === typeof method || !method) return methods.init.apply(this, arguments);
            else $.error('Method ' + method + ' does not exist on jQuery.pagination')
        });
        var $, methods
    }, {}]
}, {}, [3]);